package ReflectTest;

import AnnotationTest.MyAnnotation;
import ClassTest.Student;

/*
反射机制读取类上面的注解
 */
public class ReflectAnnotationTest1 {
    public static void main(String[] args){
        try {
            Class c = Class.forName("ClassTest.Student");
            //判断该类上是否存在MyAnnotation注解
            if(c.isAnnotationPresent(MyAnnotation.class)){
                //获取注解
                MyAnnotation myAnnotation = (MyAnnotation)c.getAnnotation(MyAnnotation.class);
                System.out.println(myAnnotation.value());//获取注解的属性值
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
